package com.moss.web;

import com.moss.common.core.BaseController;
import com.moss.common.domain.AjaxResult;
import com.moss.common.entity.SysDeptEntity;
import com.moss.system.service.DeptService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 部门管理
 * @author gxcc3
 * @date: 2024/8/28 16:37
 */
@RestController
@RequestMapping("/dept")
public class DeptController extends BaseController {

    @Resource
    DeptService deptService;


    @GetMapping("/list")
    public AjaxResult<List<SysDeptEntity>> list(SysDeptEntity dept){
        return AjaxResult.success(deptService.selectList(dept));
    }

    @GetMapping("/{deptId}")
    public AjaxResult<SysDeptEntity> selectById(@PathVariable Long deptId){
        return AjaxResult.success(deptService.selectById(deptId));
    }

    @PostMapping("/saveDept")
    public AjaxResult<Void> saveDept(@RequestBody SysDeptEntity dept){
        dept.setCreateBy(getUserId());
        deptService.saveDept(dept);
        return AjaxResult.success();
    }

    @PostMapping("/updateDept")
    public AjaxResult<Void> updateDept(@RequestBody SysDeptEntity dept){
        dept.setUpdateBy(getUserId());
        deptService.updateDept(dept);
        return AjaxResult.success();
    }

    @PostMapping("/deleteDept")
    public AjaxResult<Void> deleteDept(SysDeptEntity dept){
        dept.setUpdateBy(getUserId());
        deptService.deleteDept(dept);
        return AjaxResult.success();
    }
}
